package com.cqut.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cqut.service.ITeamMemberService;
import com.cqut.dao.TeamMemberMapper;
import com.cqut.model.TeamMember;
import com.cqut.util.SqlUtil;

@Service
public class TeamMemberService implements ITeamMemberService {
    @Resource(name="teamMemberMapper")
    private TeamMemberMapper teamMemberMapper;

    @Override
    public boolean save(TeamMember teamMember) {
        return teamMemberMapper.insert(teamMember) > 0;
    }

    @Override
    public boolean update(TeamMember teamMember) {
        return teamMemberMapper.updateByPrimaryKeySelective(teamMember) >= 0;
    }

    @Override
    public boolean delete(String teamMember) {
        return teamMemberMapper.deleteByPrimaryKey(teamMember) > 0;
    }

    @Override
    public boolean batchDelete(String[] primaryKeys) {
        return teamMemberMapper.deleteByPrimaryKeys(primaryKeys) > 0;
    }

    @Override
    public TeamMember findModel(String teamMember) {
        return teamMemberMapper.selectByPrimaryKey(teamMember);
    }

    @Override
    public TeamMember findModel(String teamMember, String[] parameters) {
        return teamMemberMapper.findModel(teamMember, SqlUtil.formatParameters(parameters));
    }

    public Map<String, Object> findMap(String teamMember) {
        String[][] parameters = {{"team_member", "teamMember"}, {"membern_name", "membernName"}, {"membern_no", "membernNo"}, {"membern_academy", "membernAcademy"}, {"type", "type"}, {"tele_phone", "telePhone"}, {"email", "email"}, {"school", "school"}};
        return this.findMap(teamMember, parameters);
    }

    public Map<String, Object> findMap(String teamMember, String[][] parameters) {
        return teamMemberMapper.findMap(teamMember, SqlUtil.formatParametersForAlias(parameters));
    }

    @Override
    public List<TeamMember> loadModels() {
        return this.loadModels(null, null, null, null, -1, -1);
    }

    @Override
    public List<TeamMember> loadModels(String condition, Object[] values, String order, String sort, int curPage, int limit) {
        return this.loadModels(null, condition, values, order, sort, curPage, limit);
    }

    @Override
    public List<TeamMember> loadModels(String[] parameters, String condition, Object[] values, String order, String sort, int curPage, int limit) {
        return teamMemberMapper.loadModels(SqlUtil.formatParameters(parameters), SqlUtil.fillCondition(condition, values), order, sort, SqlUtil.getOffset(curPage, limit), limit);
    }

    @Override
    public List<Map<String, Object>> loadMaps() {
        String[][] parameters = {{"team_member", "teamMember"}, {"membern_name", "membernName"}, {"membern_no", "membernNo"}, {"membern_academy", "membernAcademy"}, {"type", "type"}, {"tele_phone", "telePhone"}, {"email", "email"}, {"school", "school"}};
        return this.loadMaps(parameters, null, null, null, null, -1, -1);
    }

    @Override
    public List<Map<String, Object>> loadMaps(String condition, Object[] values, String order, String sort, int curPage, int limit) {
        String[][] parameters = {{"team_member", "teamMember"}, {"membern_name", "membernName"}, {"membern_no", "membernNo"}, {"membern_academy", "membernAcademy"}, {"type", "type"}, {"tele_phone", "telePhone"}, {"email", "email"}, {"school", "school"}};
        return this.loadMaps(parameters, condition, values, order, sort, curPage, limit);
    }

    @Override
    public List<Map<String, Object>> loadMaps(String[][] parameters, String condition, Object[] values, String order, String sort, int curPage, int limit) {
        return teamMemberMapper.loadMaps(SqlUtil.formatParametersForAlias(parameters), SqlUtil.fillCondition(condition, values), order, sort, SqlUtil.getOffset(curPage, limit), limit);
    }

    @Override
    public long count() {
        return this.count(null, false);
    }

    @Override
    public long count(String condition, Object[] values) {
        return this.count(null, condition, values, false);
    }

    @Override
    public long count(String[] parameters, boolean isDistinct) {
        return this.count(parameters, null, null, isDistinct);
    }

    @Override
    public long count(String[] parameters, String condition, Object[] values, boolean isDistinct) {
        return teamMemberMapper.count(SqlUtil.formatParameters(parameters), SqlUtil.fillCondition(condition, values), isDistinct);
    }

}
